package com.dz.controller.manager;

import com.dz.bean.GuideLog;
import com.dz.bean.ManagerLog;
import com.dz.bean.VisitorLog;
import com.dz.service.LogService;
import com.dz.util.Page;
import com.dz.util.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@Slf4j
@RestController
@CrossOrigin//允许跨域访问
@RequestMapping("/m/log")
public class LogManagerController {

    @Autowired
    LogService logService;

    @GetMapping("/manager")
    public Result getManagerLogs(Page page, ManagerLog log) {
        try {
            logService.pageManagerLogs(page, log);
            return Result.success(page);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error(500, "查询管理员日志失败: " + e.getMessage());
        }
    }

    @GetMapping("/guide")
    public Result getGuideLogs(Page page, GuideLog log) {
        try {
            logService.pageGuideLogs(page, log);
            return Result.success(page);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error(500, "查询导游日志失败: " + e.getMessage());
        }
    }

    @GetMapping("/visitor")
    public Result getVisitorLogs(Page page, VisitorLog log) {
        try {
            logService.pageVisitorLogs(page, log);
            return Result.success(page);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error(500, "查询游客日志失败: " + e.getMessage());
        }
    }
}
